package com.cxc.news.interceptor;


import com.cxc.news.pojo.User;
import com.cxc.news.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 管理员拦截器
 */
public class AdminInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {

        User user = (User) request.getSession().getAttribute("user");
        if (user == null){
            response.sendRedirect("/news/logins");
            return false;
        }

        if (user.getType() != 2){
            response.sendRedirect("/news/index");
            return false;
        }


        return true;
    }
}
